package com.jianneng.jdg.model.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;

import com.example.com.jianneng.jdg.R;
import com.jianneng.jdg.model.homeactivity.PhotoSActivity;

public class ConstributeAdapter extends BaseAdapter {
	private Context context;
	private LayoutInflater mInflater;
	private List<Bitmap> list=new ArrayList<Bitmap>();
	public ConstributeAdapter(Context context) {
		this.context = context;
		mInflater = LayoutInflater.from(context);
	}
	
	public void setList(List<Bitmap> list) {
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// 自定义视图
					ViewHolder holder = null;
					if (convertView == null) {
						holder = new ViewHolder();
						// 获取list_item布局文件的视图
						convertView = mInflater.inflate(
								R.layout.item_published_grida, null);

						// 获取控件对象
						holder.image = (ImageView) convertView
								.findViewById(R.id.item_grida_image);
						holder.bt = (Button) convertView
								.findViewById(R.id.item_grida_bt);
						// 设置控件集到convertView
						convertView.setTag(holder);
					} else {
						holder = (ViewHolder) convertView.getTag();
					}

					Bitmap bitmap = list.get(position);
				//	System.out.println(bmp.size()+"qqqqqqqqqqq1111111111111111");
					holder.image.setImageBitmap(bitmap);
					holder.bt.setOnClickListener(new OnClickListener() {
						public void onClick(View v) {
							PhotoSActivity.bitmap.remove(position);
							list.get(position).recycle();
							list.remove(position);
							notifyDataSetChanged();
							
						}
					});

					return convertView;
	}
	public static class ViewHolder {
		public ImageView image;
		public Button bt;
	}

}
